home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / misc / wu-ftpd-37.14.lha / wu-ftpd / src / fixes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-20  |  1.6 KB  |  76 lines

  1. /*
  2.  * This is a fixed version of lstat() from AmiTCP 3.0 beta 2.
  3.  * Author is Pekka Pessi <Pekka.Pessi@hut.fi> and the following
  4.  * copyright notice applies:
  5.  *
  6.  * Copyright © 1993,1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  7.  *             Helsinki University of Technology, Finland.
  8.  *             All rights reserved.
  9.  */
  10.  
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <errno.h>
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <sys/stat.h>
  17. #include <ios1.h>
  18. #include <proto/dos.h>
  19. #include <proto/utility.h>
  20.  
  21. #include "AmiTCP:src/netlib/netlib.h"
  22. #include "AmiTCP:src/netlib/fibex.h"
  23. #include "config.h"
  24.  
  25. int lstat(const char *name, struct stat *st)
  26. {
  27.   /* Cannot lock - do examine via Examine()/ExNext() */
  28.   int rc = -1;
  29.   char *cname;
  30.  
  31.   if (st == NULL || ((1 & (long)st) == 1)) {
  32.     errno = EFAULT;
  33.     return -1;
  34.   }
  35.  
  36.   cname = malloc(strlen(name) + 1);
  37.  
  38.   if (cname) {
  39.     BPTR lock;
  40.     char *pp = PathPart(strcpy(cname, name));
  41.     *pp = '\0';
  42.  
  43.     if (lock = Lock(cname, SHARED_LOCK)) {
  44.       pp = FilePart(name);
  45.       
  46.       if (Examine(lock, __dostat_fib)) {
  47.     while (ExNext(lock, __dostat_fib)) {
  48.       if (Stricmp(pp, __dostat_fib->fib_FileName) == 0) {
  49.         __dostat(__dostat_fib, st);
  50.         st->st_dev = (dev_t)((struct FileLock *)BADDR(lock))->fl_Task;
  51.         rc = 0;
  52.         break;
  53.       }
  54.     }
  55.       } 
  56.       if (rc != 0)
  57.     errno = ENOENT;
  58.  
  59.       /* !!! FIX !!!
  60.        * This UnLock() was missing,
  61.        * fixed 08/94 by Blaz Zupan
  62.        */
  63.       UnLock(lock);
  64.  
  65.     } else {
  66.       set_errno(IoErr());
  67.     }
  68.  
  69.     free(cname);
  70.   } else {
  71.     errno = ENOMEM;
  72.   }
  73.  
  74.   return rc;
  75. }
  76.